package cn.ecnu.mapper.forum;

import cn.ecnu.pojo.forum.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CommentMapper {

    // 增加一个评论
    int insertComment(Comment comment);

    // 获取一个内容的所有评论
    @Select("select * from pinke.comment where type_id = #{typeId} and flag = #{flag}")
    List<Comment> getCommentByTypeId(@Param("typeId") Integer typeId, @Param("flag") Integer flag);

    // 获取一个内容的所有评论, 根据点赞数目降序
    @Select("select * from pinke.comment where type_id = #{typeId} and flag = #{flag} order by like_count desc")
    List<Comment> getCommentByTypeIdOrderByHot(@Param("typeId") Integer typeId, @Param("flag") Integer flag);

    // 根据commentId获取评论
    @Select("select * from pinke.comment where comment_id = #{commentId};")
    Comment getCommentById(@Param("commentId") Integer commentId);

    // 根据commentId删除评论
    @Delete("delete from pinke.comment where comment_id = #{commentId}")
    int deleteCommentById(@Param("commentId") Integer commentId);

    // 更新一个评论, TODO: 似乎只能更新点赞数目
    @Update("update pinke.comment set like_count = #{likeCount} where comment_id = #{commentId};")
    int updateCommentById(Comment comment);

}
